<!--
* description: 关联知识
* author: zouzx
* createdDate: 2019-10-24
-->
<template>
  <section class="carTypeConfig">
    <el-dialog
      v-dialogDrag
      title="关联知识"
      :visible.sync="curPopupsVisible"
      width="1000px"
      center
      @close="sendCode"
      :close-on-click-modal="false"
      :append-to-body="true"
    >
      <dialogHeader slot="title" :title="'关联知识'" :styleType="$store.state.app.dialogType"></dialogHeader>

      <one-table-template
        ref="multipleTable"
        :dynamicButtons="tableButtons"
        :dynamicComponents="tableComponents"
        :dynamicApiConfig="apiConfig"
        :dynamicTableCols="tableCols"
        :dynamicFormFields="formField"
        :dynamicIsShowSelect="isMul"
      />
    </el-dialog>
  </section>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import { valueObjectMixins } from "@/components/mixins/valueObjectMixins";
import { crmApis } from "@/api/apiList/crm";
import OneTableTemplate from "@/components/crm/commonComponents/crmPopupsOneTable";
export default {
  // 组件混入对象：{data[listQuery] methods[queryTable]}
  mixins: [oneTableWithViewTemplateMixins, valueObjectMixins],
  components: {
    OneTableTemplate,
    dialogHeader: () => import("@/components/dialogHeader") //弹窗标题
  },
  data() {
    return {
      // 网格查询API配置对象
      apiConfig: crmApis.kmInfoQueryList, //知识查看_关联知识
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.queryTable(1),
          text: "查询",
          position: "top"
        },
        {
          compKey: "btnKey2",
          type: "primary",
          size: "small",
          clickEvent: () => this.sendZS(),
          text: "确认",
          position: "bottom"
        },
        {
          compKey: "btnKey3",
          type: "",
          size: "small",
          clickEvent: () => this.reset(),
          text: "重置",
          position: "top"
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        // 显示组件
        {
          compKey: "compKey1",
          labelName: "知识目录",
          codeField: "kmTreeId",
          component: () =>
            import("@/components/crm/crmEjectWindows/crmZSCatalog/index"),
          type: "propus",
          isMust: false,
          isMul: false
        },
        {
          compKey: "compKey2",
          labelName: "知识名称",
          codeField: "kmName",
          component: () => import("@/components/org/commonInput"),
          type: "inputText",
          isMust: true
        },
        {
          compKey: "compKey3",
          labelName: "创建时间",
          codeField: "beginDate,endDate",
          component: () => import("@/components/crm/Time/crmdtDatePicker"),
          type: "inputText",
          isMust: false
        },
        {
          compKey: "compKey4",
          labelName: "是否启用",
          codeField: "isEnable",
          component: () => import("@/components/crm/Select/crmIsEnable"),
          type: "dropdownList",
          isMust: false,
          isMul: false
        }
      ],
      // 动态生成网格列
      tableCols: [
        {
          prop: "kmTreeName",
          label: "知识目录",
          width: null,
          align: "center",
          fixed: true
        },
        {
          prop: "kmName",
          label: "知识名称",
          width: null,
          align: "center",
          fixed: true
        },
        {
          prop: "version",
          label: "当前版本",
          width: null,
          align: "center",
          fixed: true
        },
        {
          prop: "isEnableCn",
          label: "是否启用",
          width: null,
          align: "center"
        },
        {
          prop: "createdDate",
          label: "创建时间",
          width: null,
          align: "center"
        },
        {
          prop: "kmId",
          label: "kmId",
          width: null,
          align: "center",
          hidden: true
        }
      ],
      //表单查询数据（查询条件）
      formField: {
        kmTreeId: "",
        kmName: "",
        beginDate: "",
        endDate: "",
        isEnable: "1",
        queryParam: ""
      }
    };
  },
  mounted() {},
  methods: {
    sendZS() {
      let that = this;
      var selData = that.$refs.multipleTable.$refs.multipleTable.selection;
      if (selData.length > 5) {
        this.$alert("关联知识不能超过5条", "信息提示", {
          confirmButtonText: "确定",
          type: "warning",
          callback: action => {}
        });
        return;
      } else {
        this.sendCode("kmId", "kmName");
      }
    },
    reset() {
      let that = this;
      let patt = new RegExp(",");
      for (let key in that.$refs.multipleTable.$refs) {
        if (
          that.$refs.multipleTable.$refs[key][0] &&
          that.$refs.multipleTable.$refs[key][0].codeField
        ) {
          let flag = patt.test(
            that.$refs.multipleTable.$refs[key][0].codeField
          );
          if (flag) {
            that.$refs.multipleTable.$refs[key][0].modelCode = [];
          }
        }
      }
      this.formField.kmTreeId = "";
      this.reset();
    }
  }
};
</script>
